package com.deyuanyun.pic.insp.service.statistics.impl;

import com.deyuanyun.pic.common.util.StringUtils;
import com.deyuanyun.pic.insp.mapper.InspStatMapper;
import com.deyuanyun.pic.insp.service.inspresult.impl.BaseServiceImpl;
import com.deyuanyun.pic.insp.service.statistics.InspStatService;
import com.deyuanyun.pic.settings.support.biz.CodeUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 金属损失统计查询类
 *
 * @author       // scalpel.王敏
 * @version      // [v1.0] 创建时间（2016/10/14 9:22）
 * @see         // 引用的类
 * Method List:
 *         1.----------------findData 暴露方法
 *         2.----------------structurePram 参数构造方法
 * History:                           // 历史修改记录           (如果有修改别人的类，必须)   [修改人][时间][修改描述]
 */

@Service
public class InspStatServiceImpl extends BaseServiceImpl implements InspStatService {

	@Resource
	InspStatMapper inspStatMapper;

	/**
	 * 查询统计数据
	 * @param param
	 * @return
     */
	@Override
	public Map<String, Object> findData(Map<String, Object> param) {
		handlerParam(param);



		Map<String, Object> result=new HashMap<String, Object>();
		structurePram(param);
		//金属损失列表
		result.put("homeList", inspStatMapper.queryAllList(param));
		//金属损失按里程分10段查询
		result.put("lineList", inspStatMapper.queryBar(param));
		//金属损失按时钟方位查询
		result.put("timeList", inspStatMapper.queryTime(param));
		
		//--------内部金属损失--------->
		param.put("FEATURE_TYPE", CodeUtil.getCodeId("METALOSS_TYPE","内部金属损失"));
		//内部金属损失列表
		result.put("tab1List", inspStatMapper.queryDepth(param));
		//内部金属损失按里程分10段查询
		result.put("tab1LineList", inspStatMapper.queryBar(param));
		//内部金属损失按时钟方位查询
		result.put("tab1TimeList", inspStatMapper.queryTime(param));
		
		//--------外部金属损失--------->
		param.put("FEATURE_TYPE", CodeUtil.getCodeId("METALOSS_TYPE","外部金属损失"));
		//外部金属损失列表
		
		result.put("tab2List",inspStatMapper.queryDepth(param));
		//外部金属损失按里程分10段查询
		result.put("tab2LineList",inspStatMapper.queryBar(param));
		//外部金属损失按时钟方位查询
		result.put("tab2TimeList", inspStatMapper.queryTime(param));
		//--------内部制造缺陷损失--------->
		param.put("FEATURE_TYPE", CodeUtil.getCodeId("METALOSS_TYPE","内部制造缺陷"));
		//内部制造缺陷损失列表
		result.put("tab3List",inspStatMapper.queryDepth(param));
	
		//内部制造缺陷损失按里程分10段查询
		result.put("tab3LineList",inspStatMapper.queryBar(param));
		//内部制造缺陷损失按时钟方位查询
		result.put("tab3TimeList", inspStatMapper.queryTime(param));
		
		//--------外部制造缺陷损失--------->
		param.put("FEATURE_TYPE",  CodeUtil.getCodeId("METALOSS_TYPE","外部制造缺陷"));
		//外部制造缺陷损失列表
		result.put("tab4List",inspStatMapper.queryDepth(param));
	
		//外部制造缺陷损失按里程分10段查询
		result.put("tab4LineList",inspStatMapper.queryBar(param));
		//外部制造缺陷损失按时钟方位查询
		result.put("tab4TimeList", inspStatMapper.queryTime(param));
		return result;
	}


	/**
	 * 1.构造分成10等份查询的产生信
	 * 2.构造金属损失峰值深度（%wt） 参数
	 * @param param
     */
	private void structurePram(Map<String, Object> param)
	{
		//从map中取出页面传递过来的里程参数信息
		Double beginMileage= (Double) param.get("beginMileage");
		Double endMileage= (Double) param.get("endMileage");


		//假定里程信息都是数字
		Double dbeginMileage=beginMileage;
		Double dendMileage=endMileage;

		//每等份绝对里程的长度
		Double average=(dendMileage-dbeginMileage)/10;

		//里程查询对象
		List<AssistQuery> queryList=new ArrayList<AssistQuery>();
		for(int i=1;i<=10;i++)
		{
			Double end=dbeginMileage+average;
			if(i == 10)
			{
				end=dendMileage;
			}
			queryList.add(new AssistQuery(dbeginMileage,end,""+Math.floor(end)));
			dbeginMileage=end;
		}
		param.put("queryList",queryList);


		//开始构造金属损失峰值深度查询
		List<AssistQuery> deptList=new ArrayList<AssistQuery>();
		deptList.add(new AssistQuery(0d,10d,"1"));
		deptList.add(new AssistQuery(10d,20d,"2"));
		deptList.add(new AssistQuery(20d,30d,"3"));
		deptList.add(new AssistQuery(30d,40d,"4"));
		deptList.add(new AssistQuery(40d,50d,"5"));
		deptList.add(new AssistQuery(50d,null,"6"));
		deptList.add(new AssistQuery(1d,null,"7"));
		param.put("deptList",deptList);

		//构造内外部金属损失总查询
		//开始构造金属损失峰值深度查询
		List<AssistQuery> List=new ArrayList<AssistQuery>();
		List.add(new AssistQuery(1d,null, CodeUtil.getCodeId("METALOSS_TYPE","外部金属损失")));
		List.add(new AssistQuery(2d,null, CodeUtil.getCodeId("METALOSS_TYPE","内部金属损失")));
		List.add(new AssistQuery(3d,null, CodeUtil.getCodeId("METALOSS_TYPE","外部制造缺陷")));
		List.add(new AssistQuery(4d,null, CodeUtil.getCodeId("METALOSS_TYPE","内部制造缺陷")));
		param.put("allList",List);

		//查询金属损失分类
		List<String> typeList=new ArrayList<String>();
		typeList.add(CodeUtil.getCodeId("METALOSS_TYPE","外部金属损失"));
		typeList.add(CodeUtil.getCodeId("METALOSS_TYPE","内部金属损失"));
		typeList.add(CodeUtil.getCodeId("METALOSS_TYPE","外部制造缺陷"));
		typeList.add(CodeUtil.getCodeId("METALOSS_TYPE","内部制造缺陷"));
		param.put("typeList",typeList);



		//制造时间查询参数
		List<String> timeList=new ArrayList<String>();
		timeList.add("00");
		timeList.add("01");
		timeList.add("02");
		timeList.add("03");
		timeList.add("04");
		timeList.add("05");
		timeList.add("06");
		timeList.add("07");
		timeList.add("08");
		timeList.add("09");
		timeList.add("10");
		timeList.add("11");
		timeList.add("12");
		param.put("timeList",timeList);

	}




	/**
	 * 辅助查询类
	 * 定义查询类型，
	 * 定义查询起止里程
	 * 勇于方便传递sql进行查询
	 */
	public class  AssistQuery
	{
			//区间信息
			Double begin=0d;
			Double end=0d;

			//查询展示名称
			String name="";

			//定义类构造函数
			public AssistQuery(Double begin,Double end,String name)
			{
				this.begin=begin;
				this.end=end;
				this.name=name;
			}

		public Double getBegin() {
			return begin;
		}

		public Double getEnd() {
			return end;
		}

		public String getName() {
			return name;
		}
	}


}
